<?php

namespace App\Models;

use App\Models\Rbac\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Purchase extends BaseModel
{
    use HasFactory;
    protected $table = 'purchase';
    // 允许批量操作的字段
    protected $fillable = [
        'purchase_number',
        'order_id',
        'is_del',
        'status',
        'buyer',
        'created_at',
        'updated_at',
        'status'
    ];

    public function scopeSearch($query,$params)
    {
        return $query;
    }

    public function order(){
        return $this->hasOne(Order::class,'id','order_id');
    }

    public function buyers(){
        return $this->hasOne(User::class,'id','buyer');
    }

    public function child(){
        return $this->hasMany(PurchaseChild::class,'purchase_id','id');
    }
}
